package gov.pbc.nn.kjgl.joinjrfwygl.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import gov.pbc.nn.core.dao.AbstractHibernateDao;
import gov.pbc.nn.kjgl.joinjrfwygl.entity.HandleDept;
import gov.pbc.nn.kjgl.joinjrfwygl.entity.HandleInfo;
import gov.pbc.nn.kjgl.joinjrfwygl.entity.JoinJrfwygl;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.bstek.dorado.data.provider.Criteria;
import com.bstek.dorado.data.provider.Page;

@Repository
public class JoinJrfwyglDao extends AbstractHibernateDao {

	
	public List<HandleDept> getHandleDepts(String id) {
		String hql = "from " + HandleDept.class.getName() + " where joinId=:id and invalid=false";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("id", id);
		return this.query(hql, params);
	}

	public HandleInfo getHandleInfo(String id) {
		String hql = "from " + HandleInfo.class.getName() + " where handleDeptId=:id and invalid=false";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("id", id);
		List<HandleInfo> query = this.query(hql, params);
		if(query.size()>0){
			return query.get(0);
		}else{
			return null;
		}
	}

	public void getJoinJrfwyglPage(Page<JoinJrfwygl> page, Criteria criteria) {
		DetachedCriteria query = this.buildDetachedCriteria(criteria, JoinJrfwygl.class);
		query.add(Restrictions.or(Restrictions.eq("invalid", false), Restrictions.isNull("invalid")));
		// query.add(Restrictions.eq("createUser",
		// ContextHolder.getLoginUser().getUsername()));
		this.pagingQuery(page, query);
	}
}
